package com.hospital.service.impl;

import com.hospital.dao.EqucheckDao;
import com.hospital.dao.EquipmentDao;
import com.hospital.dto.EqucheckDto;
import com.hospital.entity.Equcheck;

import com.hospital.service.intf.EqucheckService;
import com.hospital.vo.PageBean;
import com.hospital.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EqucheckServiceImpl implements EqucheckService {
    @Autowired
    private EqucheckDao dao;
    @Autowired
    private EquipmentDao equipmentdao;

    @Override
    public R add(Equcheck equcheck) {
        if (equipmentdao.selectById(equcheck.getEquid()) != null) {
            if (dao.add(equcheck) > 0) {
                return R.ok();
            } else {
                return R.fail();
            }
        } else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, Date ctime, int page, int limit) {
        int start =(page-1)*limit;
        if(name!=null){
            name="%"+name+"%";
        }
        return PageBean.ok(dao.selectCount(name,ctime),dao.selectPage(start,limit,name,ctime));

    }


    @Override
    public R seletime(Date ctime) {
        if (dao.seletime(ctime)!=null){
            return R.ok();
        }else {
            return R.fail();
        }
    }




    @Override
    public List<EqucheckDto> all1() {
        return dao.all2();
    }

    @Override
    public R deleids(int[] ids) {
        if (dao.deleids(ids)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean checkLog(String name,Integer page,Integer limit) {
        int start =(page-1)*limit;
        if(name!=null){
            name="%"+name+"%";
        }
        return PageBean.ok(dao.countlog(name),dao.queryCheckLog(start,limit,name));

    }
}
